package com.example.demo.controller;

import com.example.demo.annotate.Lock;
import com.example.demo.common.Func;
import com.example.demo.common.Result;
import com.example.demo.common.Valid;
import com.example.demo.common.constant.RuleCode;
import com.example.demo.entity.dto.CompanyDTO;
import com.example.demo.entity.dto.UserDTO;
import com.example.demo.entity.vo.EncryptVO;
import com.example.demo.service.CompanyService;
import com.example.demo.verify.NoEmpty;
import com.example.demo.verify.NoMobile;
import com.example.demo.verify.ParamValid;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/company")
@Api(tags = "6、供应商管理")
@ApiSupport(author = "罗海林", order = 6)
@Validated
@RequiredArgsConstructor
public class CompanyController {

    private final CompanyService companyService;

    @PostMapping("/getCompanyList")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "title", value = "标题"),
            @ApiImplicitParam(name = "phone", value = "手机号"),
            @ApiImplicitParam(name = "creater", value = "创建者")
    })
    @ApiOperation(value = "获取供应商列表", response = Result.class)
    @ApiOperationSupport(author = "罗海林", order = 1)
    public Result getCompanyList(@NoEmpty(message = "标题不能为空") String title,
                                 @NoMobile(message = "手机号格式不正确") String phone,
                                 @NoEmpty(message = "创建者不能为空") String creater) {

        Valid.StringNotEmpty(creater, "创建者的格式不是很正确，请重新录入");
        Valid.StringIsEquals(creater, "王彦远", "创建者不等于指定人员");
        Valid.StringIsEquals(creater, new String[]{"南湘", "小野"}, "创建者不等于指定的多个人员");

        Func.print("执行到这了");

        return companyService.getCompanyList(title, phone, creater);
    }

    @PostMapping("/getUserList")
    @ApiOperation(value = "获取用户列表", response = Result.class)
    @ApiOperationSupport(author = "罗海林", order = 2)
    public String getUserList(@RequestBody @Validated UserDTO userDTO) {
        return companyService.getUserList(userDTO);
    }

    @PostMapping("/addUser")
    @ApiOperation(value = "添加用户信息", response = Result.class)
    @ApiOperationSupport(author = "罗海林", order = 3)
    public String addUser() throws Exception {
        return companyService.addUser();
    }

    @PostMapping("/editUser")
    @ApiOperation(value = "编辑用户信息", response = Result.class)
    @ApiOperationSupport(author = "罗海林", order = 4)
    public String editUser() {
        return companyService.editUser();
    }




    @PostMapping("/addCompeny")
    @ApiOperation(value = "增加企业信息", response = Result.class)
    @ApiOperationSupport(author = "罗海林", order = 21, ignoreParameters = { "companyId" })
    public String addCompeny(@RequestBody @Validated({ CompanyDTO.Add.class }) CompanyDTO companyDTO) {
        return "";
    }

    @PostMapping("/editCompeny")
    @ApiOperation(value = "编辑企业信息", response = Result.class)
    @ApiOperationSupport(author = "罗海林", order = 22)
    public String editCompeny(@RequestBody @Validated({ CompanyDTO.Edit.class }) CompanyDTO companyDTO) {
        return "";
    }

    @PostMapping("/delCompeny")
    @ApiOperation(value = "删除企业信息", response = Result.class)
    @ApiOperationSupport(author = "罗海林", order = 23, ignoreParameters = { "companyId","address","money","creater","sendtime" })
    public String delCompeny(@RequestBody @Validated({ CompanyDTO.Delete.class }) CompanyDTO companyDTO) {
        return "";
    }

    @PostMapping("/getCompenyInfo")
    @ApiOperation(value = "获取企业信息", response = Result.class)
    @ApiOperationSupport(author = "罗海林", order = 24, includeParameters = { "companyId", "sendtime" })
    public String getCompenyInfo(@RequestBody @Validated({ CompanyDTO.Info.class }) CompanyDTO companyDTO) {
        return "";
    }

    @PostMapping("/findCompeny")
    @ApiOperation(value = "查询企业信息", response = Result.class)
    @ApiOperationSupport(author = "罗海林", order = 25, ignoreParameters = { "companyId","address","money","creater","sendtime" })
    public String findCompeny(@RequestBody @Validated({ CompanyDTO.Query.class }) CompanyDTO companyDTO) {
        return "";
    }



    @PostMapping("/getTenderList")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "title", value = "标题"),
            @ApiImplicitParam(name = "mobile", value = "手机号"),
            @ApiImplicitParam(name = "phone", value = "电话"),
            @ApiImplicitParam(name = "money", value = "支付金额"),
            @ApiImplicitParam(name = "count", value = "学生人数")
    })
    @ApiOperation(value = "获取标书列表", response = Result.class)
    @ApiOperationSupport(author = "王彦远", order = 31)
    @Lock
    public String getTenderList(@ParamValid(name = "标题", rule = RuleCode.noEmpty) String title,
                                @ParamValid(name = "手机号", rule = RuleCode.mobile) String mobile,
                                @ParamValid(name = "座机电话", rule = RuleCode.phone) String phone,
                                @ParamValid(name = "支付金额", rule = RuleCode.money) String money,
                                @ParamValid(name = "学生人数", rule = RuleCode.num, empty = true) String count) {
        return "校验成功";
    }

    @PostMapping("/PrivacyEncrypt")
    @ApiOperation(value = "字段脱敏", response = Result.class)
    @ApiOperationSupport(author = "伍南湘", order = 32)
    public EncryptVO PrivacyEncrypt() {
        EncryptVO vo = new EncryptVO() {{
            setUsername("luohailin860323");
            setIdcard("450502198603230316");
            setPhone("3072596");
            setMobile("13507797221");
            setAddress("北海市海城区贵州路屋仔村二十一巷13号");
            setEmail("543982146@qq.com");
            setBankcard("4563512600683239892");
            setPassword("lhlysyl543214Dahai");
            setKey("66dOYvnMaLyNMnz2");
        }};

        return vo;
    }
}
